#include <string_ref>

#include "assert.h"
#include <string>

constexpr std::string_ref hello("hello", 5);

void test_wstring_ref() {
    std::wstring ws = L"abcd";
    std::wstring_ref wsr = ws;
    assert(wsr.compare(L"abd") < 0);
    assert(wsr.compare(ws) == 0);
    assert(wsr.starts_with(L"ab"));
    assert(wsr.ends_with(L"cd"));

    wsr = L"Hello World";
    assert(wsr.find(L'l') == 2);
    assert(wsr.rfind(L'l') == 9);
    assert(wsr.find(L"lo") == 3);
}

template<bool b> struct CompileAssert;
template<> struct CompileAssert<true> {};

void test_constexpr() {
    constexpr std::string_ref sr("Hello World", 11);
    constexpr std::string_ref ello = sr.substr(1, 5);
    CompileAssert<ello[2] == 'l'>();
    CompileAssert<ello.front() == 'e'>();
}

int main() {
    test_wstring_ref();
    test_constexpr();
}
